package com.itheima.exerciseTest.method10_19.method18;

import java.io.*;

public class UserDemo1 {
    public static void main(String[] args) {
        User u1 = new User("aaaaa","11111");
        User u2 = new User("bbbbb","22222");
        User u3 = new User("ccccc","33333");

        ObjectOutputStream oos = null;
        try {
            oos = new ObjectOutputStream(new FileOutputStream("backBurner\\e.txt"));
            oos.writeObject(u1);
            oos.writeObject(u2);
            oos.writeObject(u3);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("backBurner\\e.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        while (true) {
            try {
                Object o = ois.readObject();
                User u = (User) o;
                System.out.println(u);
            } catch (IOException | ClassNotFoundException e) {
                break;
            }
        }
        if (ois != null) {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
